import fetch from '@/utils/network/fetch'
import formPost from '@/utils/network/formPost'
const state = {
    data: {
        digitalListdata: '',
        summonsData: '',
        GradesData: '',
        digitalExamData: '',
        onceExamData: []
    }
}

// getters
const getters = {
    digitalListdata: state => state.data.digitalListdata,
    summonsData: state => state.data.summonsData,
    GradesData: state => state.data.GradesData,
    digitalExamData: state => state.data.digitalExamData,
    onceExamData: state => state.data.onceExamData
}

// 获取打字数据
const actions = {
    digitalList({ commit }, objc) {
        fetch('/api/digital/digital_input', {
            showError: true,
            method: 'get',
            success: res => {
                commit('SETDATA', res)
                objc && objc.success && objc.success(res)
            }
        })
    },
    // 获取传票翻打数据
    summonsFn({ commit }, objc) {
        const URL = location.href
        const URL_FLAG = URL.includes('citation_fixed')
        const summonsUrl = URL_FLAG ? '/api/csv/play_citation' : '/api/digital/summons'
        fetch(`${summonsUrl}`, {
            showError: true,
            method: 'get',
            success: res => {
                objc && objc.success && objc.success(res)
            }
        })
    },
    // 上传成绩
    uploadGradesFn({ commit }, objc) {
        fetch('/api/digital/typing_result', {
            showError: true,
            method: 'put',
            data: objc.data,
            success: res => {
                commit('SETGRADES', res)
                objc && objc.success && objc.success(res)
            }
        })
    },
    obtainExamResult({ commit }, objc) {
        fetch('/api/digital', {
            showError: true,
            method: 'post',
            data: objc.data,
            success: res => {
                commit('SETDIGITALDATA', res)
                objc && objc.success && objc.success(res)
            }
        })
    },
    obtainOneExam({ commit }, data, objc) {
        console.log(objc)
        fetch(`/api/digital/exam_detail?examId=${data.examId}&employeeId=${data.employeeId}`, {
            success: res => {
                let data = []
                data.push(res)
                commit('SETONCEEXAM', data)
                objc && objc.success && objc.success(res)
            }
        })
    }
}
// mutations
const mutations = {
    SETDATA: (state, payload) => {
        state.data.digitalListdata = payload
    },
    SETSUMMONS: (state, payload) => {
        state.data.summonsData = payload
    },
    SETGRADES: (state, payload) => {
        state.data.GradesData = payload
    },
    SETDIGITALDATA: (state, payload) => {
        state.data.digitalExamData = payload
    },
    SETONCEEXAM: (state, payload) => {
        state.data.onceExamData = payload
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}
